using System;
using System.Collections.Generic;
using System.Text;
using Technoera.Common.Entities.SpecialCase;
using System.Reflection;
using NHibernate;

namespace Technoera.Common.Nh.CustomPropertyAccessors
{
    public class SpecialCaseFieldGetter : FieldGetterBase
    {
        public SpecialCaseFieldGetter(FieldInfo field, System.Type clazz, string name)
            : base(field, clazz, name)
        {
        }

        public override object Get(object target)
        {
            try
            {
                object value = field.GetValue(target);
                if (value is ISpecialCase)
                {
                    return null;
                }
                else
                {
                    return value;
                }
            }
            catch (Exception e)
            {
                throw new PropertyAccessException(e, "could not get a field value by reflection", false, clazz, name);
            }
        }
    }
}
